// pages/map/map.js
import { areaList } from '@vant/area-data'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    areaList, // 地区数据
    height: '',
    minHeight: 250,
    markers: [
      {
        id: 1,
        longitude: '116.410593',
        latitude: '39.909622',
        iconPath: '/static/images/store/marker.png',
        width: '56rpx',
        height: '68rpx',
        callout: {
          display: 'ALWAYS',
          content: '3km | 成都钻石广场店 即将开业',
          color: '#2E374C',
          fontSize: 12,
          borderRadius: 40,
          bgColor: '#FFFFFF',
          padding: 10,
        }
      },
      {
        id: 2,
        longitude: '116.413593',
        latitude: '39.909912',
        iconPath: '/static/images/store/marker-active.png',
        width: '56rpx',
        height: '68rpx',
        callout: {
          display: 'ALWAYS',
          content: '3km | 成都钻石广场店',
          color: '#4484FF',
          fontSize: 12,
          borderRadius: 40,
          bgColor: '#FFFFFF',
          padding: 10,
        }
      }
    ],
    showDetail: false, // true 展示详情
    showCallPhone: false, // 拨打电话弹窗
    actions: [
      {
        name: '13312341234',
      },
      {
        name: '呼叫',
      },
    ],
    showRegionPicker: false, // 地区选择
    areaName: '成都市'
  },
  touchstart(e) {
    // console.log('touchStart', e)
    this.startY = e.touches[0].clientY; // 获取触摸时的x坐标

  },
  touchmove(e) {
    const y = e.touches[0].clientY; // 获取触摸时的x坐标
    const moveY = this.startY - y
    if (moveY > 0 && this.data.height >= this.windowHeight) {
      return
    } else if (moveY < 0 && this.data.height <= this.data.minHeight) {

      return
    }
    this.setData({
      height: this.data.height + moveY
    })
    console.log('moveY', moveY)
    this.startY = y
  },
  // 列表项点击事件
  handleItemClick() {
    this.setData({
      showDetail: true
    })
  },
  // 点击电话
  handleCallPhoneClick() {
    this.setData({
      showCallPhone: true
    })
  },
  // 选择拨打电话
  handleCallPhoneSelect(event) {
    console.log(event.detail)
  },
  // 关闭拨打电话弹窗
  handleCallPhoneClose() {
    this.setData({ showCallPhone: false })
  },
  handleShowRegionPickerClick() {
    this.setData({ showRegionPicker: true })
  },
  handleHideRegionPickerClick() {
    this.setData({ showRegionPicker: false })
  },
  handleHideRegionPickerConfirm(event) {
    this.handleHideRegionPickerClick()
    console.log(event.detail);
    const { values } = event.detail
    this.setData({ areaName: values[values.length - 1].name })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let query = wx.createSelectorQuery()
    query.select('.store-list').boundingClientRect(rect => {
      this.currentstoreListHeight = rect.height;
      this.setData({
        height: rect.height
      })
      console.log(rect.height);
    }).exec()
    this.windowHeight = wx.getSystemInfoSync().windowHeight
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})